package com.gzl.gg.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.gxl.butt.utils.JSONUtils;
import com.gzl.gg.values.StaticValue;
import com.gzl.myapi.service.IDotestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/**
 * Backend controller used to monitor and restart the KClient.
 *
 * @author guoxiaolin
 * @since Aug 21, 2015
 *
 */
@Api(value = "controller operator",tags = "controller operator")
@RestController
@RequestMapping(value = "/testContr")
public class TestController {

	private  Logger log = LoggerFactory.getLogger(TestController.class);

//	@Reference(interfaceClass = IkafkaOperatorService.class,timeout = 10000,check = false)
//	private IkafkaOperatorService kafkaOperatorService;
//
//	@Reference(interfaceClass = IIPService.class,timeout = 10000,check = false)
//	private IIPService iipService;
//
	@Reference(interfaceClass = IDotestService.class,timeout = 10000,check = false)
	private IDotestService iDotestService;

	@Autowired
	private RedisTemplate redisTemplate;
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;


	@ApiOperation(value="測試函數", notes="testMethods測試函數")
	@RequestMapping(value = "/testMethods",method = RequestMethod.GET)
	public JSONObject testMethods(){

		iDotestService.updateDotest();
		log.info("---------------------------------------------------------------------------------------------" + StaticValue.MUB++);
//		if (StaticValue.MUB==50){
//			try {
//				Thread.sleep(5000);
//				System.out.println("數量達到50 ，休息一下5秒");
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//		}
		Thread t1  = new Thread(new Runnable() {
			@Override
			public void run() {
			while (true) {
				System.out.println("0");
			}
			}
		});
		t1.start();
		synchronized (t1) {
			try {
				t1.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		return JSONUtils.getRoot(0,"MSG","");

	}

}